/**
 * @description TransportModel Service
 */

const {
  TransportModel
} = require('../db/index')
const Op = require('sequelize').Op

/**
 * 新用户注册
 * @param {string} userid 用户id
 * @param {string} nikename 昵称
 * @param {string} city 城市
 * @param {number} isVip 是否VIP
 * @param {string} createtime 注册时间
 */
async function addData(params) {
  const result = await TransportModel.create(params)
  const data = result.dataValues
  return data
}

/**
 * 分页查询所有用户
 * @param {number} page 当前页码
 * @param {number} pageSize 每页条数
 */
async function queryAll(params) {
  const {
    transfer_vehicle_id,
    transfer_person_id,
    package_id
  } = params
  let whereOption = {}
  if (transfer_vehicle_id) {
    whereOption.transfer_vehicle_id = {
      [Op.like]: `%${transfer_vehicle_id}%`
    }
  }
  if (transfer_person_id) {
    whereOption.transfer_person_id = {
      [Op.like]: `%${transfer_person_id}%`
    }
  }
  if (package_id) {
    whereOption.package_id = package_id
  }


  const result = await TransportModel.findAll({
    where: whereOption
  })

  return {
    count: result.count,
    data: result
  }
}

module.exports = {
  addData,
  queryAll,
}